package test.proxy.vehicle;

import java.lang.reflect.*;

/**
 * Class Client3. Interacts with a Car Vehicle through a dynamically generated
 * VehicleProxy.
 */
public class Client3 {
	public static void main(String[] pars) {
		IVehicle c = new Car("Botar");
		// ClassLoader cl = IVehicle.class.getClassLoader();
		// IVehicle v = (IVehicle) Proxy.newProxyInstance(cl,
		// new Class[] { IVehicle.class }, new VehicleHandler(c));
		// v.start();
		// System.out.println(v.forward(9,8));
		// v.stop();

		Class ownerClass = c.getClass();
		Object[] args = { Integer.valueOf(7), Integer.valueOf(8) };
		Class[] argsClass = new Class[args.length];

		for (int i = 0, j = args.length; i < j; i++) {
			argsClass[i] = args[i].getClass();
		}
		try {
			Method method = ownerClass.getMethod("forward", argsClass);
			try {
				Object o = method.invoke(c, args);
				System.out.println(o);
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
